<?php
class DiemdanhsController extends AppController {

	var $name = 'Diemdanhs';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Diemdanh->recursive = 0;
		$this->set('diemdanhs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Diemdanh', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('diemdanh', $this->Diemdanh->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Diemdanh->create();
			if ($this->Diemdanh->save($this->data)) {
				$this->Session->setFlash(__('The Diemdanh has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Diemdanh could not be saved. Please, try again.', true));
			}
		}
		$sinhviens = $this->Diemdanh->Sinhvien->find('list');
		$thuchanhs = $this->Diemdanh->Thuchanh->find('list');
		$giaoviens = $this->Diemdanh->Giaovien->find('list');
		$this->set(compact('sinhviens', 'thuchanhs', 'giaoviens'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Diemdanh', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Diemdanh->save($this->data)) {
				$this->Session->setFlash(__('The Diemdanh has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Diemdanh could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Diemdanh->read(null, $id);
		}
		$sinhviens = $this->Diemdanh->Sinhvien->find('list');
		$thuchanhs = $this->Diemdanh->Thuchanh->find('list');
		$giaoviens = $this->Diemdanh->Giaovien->find('list');
		$this->set(compact('sinhviens','thuchanhs','giaoviens'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Diemdanh', true));
			$this->redirect(array('action' => 'index'));
		}
		if ($this->Diemdanh->del($id)) {
			$this->Session->setFlash(__('Diemdanh deleted', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('The Diemdanh could not be deleted. Please, try again.', true));
		$this->redirect(array('action' => 'index'));
	}

}
?>